#include<iostream>
#include<functional>
#include<algorithm>
#include<vector>
using std::mem_fn;
using std::vector;
using std::endl;
using std::cout;
using std::function;
using std::bind;
using std::for_each;
//使用bind

class Point
{
//用c11的写法
using DisplayCallback = function<void()>;
public:
void setDisplayCallback(DisplayCallback &&cb){
    _displayCallback = std::move(cb); //执行回调函数
}

private:
    DisplayCallback _displayCallback;

public:
    Point() = default;
    Point(int x,int y);
    ~Point();
    void Print();
    
private:
    int _x;
    int _y;

};

Point::Point(int x,int y)
:_x(x)
,_y(y)
{
    cout << "Point(int x,int y)"<<endl;
}
Point::~Point()
{
    cout<<"~Point"<<endl;
}
void Point::Print(){
    cout<<"Point "<<_x<<" "<<_y<<endl;
}

class Point3D
:public Point
{
private:
    int _z;
public:
    Point3D(int x,int y,int z);
    ~Point3D();
    void print();
    void display(){
        cout<<_z<<endl;
    }

};

Point3D::Point3D(int x,int y,int z)
:Point(x,y)
,_z(z)
{
    cout << "Point3D(int x,int y,int z)"<<endl;
}
Point3D::~Point3D()
{
    cout<<"~Point3D()"<<endl;
}
void Point3D::print(){
    Point::Print();
    cout<<_z<<endl;
}
void FuncPrint(int &data){
    cout<<data<<endl;
}


int test0(){
    vector<int> numbers = {1,2,3,5,3,5,8,6};
    using namespace std::placeholders;
    for_each(numbers.begin(),numbers.end(),bind(FuncPrint,_1));
}

int test2(){
    Point p1;
    Point3D p2(1,2,3);
    p1.setDisplayCallback(bind(&Point3D::print,&p2));    
}

int main(void){
    test2();
}